Repository navigation
Intersections: compute sweep fields bottom-up along the status for overlapping segments - #392
anaelorlinski wants to merge 1 commit into
Conversation
…erlapping segments The sweep fields of the left-endpoints in a tolerance square are computed in CompareH order, each from the segment below it in the sweep status. Windings propagate bottom-up along the status, so this is only correct when the two orders agree. For overlapping segments that start in the same point they need not: a segment can then read the windings of a neighbour that has not been computed yet, gets zeros, and every segment above the stack inherits the error. mergeOverlapping later recomputes the merged stack itself, but not the segments above it, so the result polygon walk arrives at a vertex on a boundary segment and finds no segment leaving it: "next node for result polygon is nil" in debug mode, a silently truncated contour otherwise. Compute a left-endpoint's fields only after those of the segment below it when that segment starts in the same point, and mark computed endpoints so a segment is never computed twice. Split pieces start unmarked. This is the failure behind tdewolff#382: the stroke outline of a merged grid of nearly-exact cells, where the outlines of adjacent cells overlap exactly along shared edges. The fixture from that PR now settles to the outer square in debug mode. The regression test builds equivalent geometry from a seeded grid with 1e-17 corner noise; four seeds panic before this change and settle to a single square of area 1.44 after it. Not addressed: some noisier grids hit "first segment became vertical and needs reversal, but was already in the sweep status", which is a different failure. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Was the fix wrong for both PRs? |
|
The 2 fixes improve the intersections computation but there are still other issues on the algorithm after applying them. In parallel I made Claude work on a different approach to use an algorithm that work with integers and the results are promising (better speed and accuracy) : Claude ported Clipper2 from Go to C++, made it work on fixing the issues found in the Github, ported test suites from various similar projects (iOverlay, polygon-clipping). You can have a look at the repo but there is still pending items and few items to investigate in canvas test suite (everything else passes). |
While reviewing my panic workarounds in canvas intersection (mainly workaround by adding perturbation at clip bounds) I made claude work ok the #382 issue because it was integrated in my fork.
Seems to be the fix for it but I don't have the proper knowledge to confirm.